﻿@using System.Reflection
@using Gurux.DLMS.AMI.Client.Helpers.Toaster
@using Microsoft.AspNetCore.Components.Routing

@inject GXModuleService modules

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(App).Assembly" AdditionalAssemblies="@assemblies">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    @if (context.User.Identity?.IsAuthenticated != true)
                    {
                        <RedirectToLogin />
                    }
                    else
                    {
                        <p>@Properties.Resources.NotAuthorized</p>
                    }
                </NotAuthorized>
            </AuthorizeRouteView>
            <FocusOnNavigate RouteData="@routeData" Selector="h1" />
        </Found>
        <NotFound>
            <PageTitle>Not found</PageTitle>
            <LayoutView Layout="@typeof(MainLayout)">
                <p>@Properties.Resources.InvalidHttpAddress.</p>
            </LayoutView>
        </NotFound>
    </Router>
</CascadingAuthenticationState>
<Toaster />
@code {
    public static List<Assembly>? assemblies = null;

    protected override void OnInitialized()
    {
        assemblies = modules.Assemblies;
    }
}